//
//  GFHomeView.m
//  GoodFood
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 荣伟峰. All rights reserved.
//

#import "GFHomeView.h"


@interface GFHomeView ()

@end

@implementation GFHomeView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self creatScrollView];
        [self creatImageView];
        [self creatLabel];
        

        
        
    }
    return self;
}


- (void)creatScrollView {
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, self.frame.size.height - ScreenWidth / 375 * 70)];
    self.scrollView.contentSize = CGSizeMake(ScreenWidth * 10, 0);
    self.scrollView.pagingEnabled = YES;
    [self addSubview:self.scrollView];
   
}

- (void)creatImageView {
    for (int i = 0; i < 10; i++) {
        self.addView = [[GFBaseView alloc] initWithFrame:CGRectMake(ScreenWidth * i, 0, ScreenWidth, self.frame.size.height)];
        self.addView.tag = i + 10;
        [self.scrollView addSubview:self.addView];
 
    }
    for (int i = 0; i < 10; i++) {
        self.addView = (GFBaseView *)[self viewWithTag:i + 10];
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, self.frame.size.height)];
        self.imageView.tag = i + 1000;
        self.imageView.backgroundColor = [UIColor whiteColor];
        [self.addView addSubview:self.imageView];

    }
}

- (void)setImageArr:(NSArray *)imageArr {
    if (_imageArr != imageArr) {
        
        _imageArr = imageArr;
    }
    
    /* 给label和imageView赋值 */
    for (int i = 0; i < 10; i++) {
        self.imageView = (UIImageView *)[self viewWithTag:i + 1000];
        self.foodLabel = (UILabel *)[self viewWithTag:i + 100];
        GFHomeModel *model = imageArr[i];
        [self.imageView setImageWithURL:[NSURL URLWithString:model.image_url] placeholderImage:[UIImage imageNamed:@"category_1"]];
        self.foodLabel.text = model.food_name;
        CGFloat h = [GFCalculateWidthOrHeigth stringHeight:model.food_name withWidth:ScreenWidth / 375 * 20 withFontDictionary:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:20]}];
        self.foodLabel.frame = CGRectMake(ScreenWidth / 375 * 290, ScreenWidth / 375 * 20, 20, h);
    }
}

/* 展示区上部随展示区变化的标题 */
- (void)creatLabel {
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, ScreenWidth / 375 * 350, ScreenWidth, ScreenWidth / 375 * 40)];
    self.titleLabel.font = [UIFont systemFontOfSize:22];
    self.titleLabel.text = @"这里是吃货的世界";
    
    [self addSubview:self.titleLabel];

    
    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, ScreenWidth / 375 * 390, ScreenWidth, ScreenWidth / 375 * 30)];
    self.contentLabel.font = [UIFont systemFontOfSize:15];
    self.contentLabel.textColor = [UIColor lightGrayColor];
    self.contentLabel.text = @"看看奇葩的营养吃法......";
    
    [self addSubview:self.contentLabel];

    
    for (int i = 0; i < 10; i++) {
        self.imageView = (UIImageView *)[self viewWithTag:i + 1000];
        self.foodLabel = [[UILabel alloc] init];
        self.foodLabel.tag = i + 100;
        self.foodLabel.numberOfLines = 0;
        [self.imageView addSubview:self.foodLabel];
        self.foodLabel.backgroundColor = [UIColor whiteColor];
        self.foodLabel.alpha = 0.5;
        self.foodLabel.layer.cornerRadius = 5;
        self.foodLabel.layer.masksToBounds = YES;
        self.foodLabel.font = [UIFont boldSystemFontOfSize:20];

    }
}

@end
